<?php
App::uses('AppModel', 'Model');
/**
 * Venue Model
 *
 * @property SysWebsite $SysWebsite
 * @property SysCity $SysCity
 * @property SysArea $SysArea
 * @property SysPhoto $SysPhoto
 * @property VenueGallery $VenueGallery
 */
class Venue extends AppModel {

	public $displayField = 'title_cn';
/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'sys_website_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'sys_city_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'sys_area_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'title_cn' => array(
			'notEmpty' => array(
				'rule' => array('notEmpty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'sort' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		)
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'SysWebsite' => array(
			'className' => 'SysWebsite',
			'foreignKey' => 'sys_website_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'SysCity' => array(
			'className' => 'Areas.SysArea',
			'foreignKey' => 'sys_city_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'SysSeo' => array(
				'className' => 'SysSeo',
				'foreignKey' => 'sys_seo_id',
				'conditions' => '',
				'fields' => '',
				'order' => ''
		),
		'SysArea' => array(
			'className' => 'Areas.SysArea',
			'foreignKey' => 'sys_area_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'SysPhoto' => array(
			'className' => 'SysPhoto',
			'foreignKey' => 'sys_photo_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

/**
 * hasMany associations
 *
 * @var array
 */
	public $hasMany = array(
		'VenueGallery' => array(
			'className' => 'VenueGallery',
			'foreignKey' => 'venue_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);
	
	public function getSiteEnableVenue($sys_website_id){
		return $this->find('list',array('conditions'=>array(
				'Venue.enable'=>1,
				'Venue.sys_website_id'=>$sys_website_id
			),
			'order'=>'Venue.sort_top DESC,Venue.sort DESC'
		));
	}

	public function getPai($sys_website_id){
		$this->unbindModel(array(
				'hasMany'=>array('VenueGallery')
		));
		$venue =$this->find('all',array(
			'conditions'=>array(
				'Venue.sort_top'=>1,
				'Venue.sys_website_id'=>$sys_website_id
			),
			'limit'=>3,
			'order'=>'Venue.sort DESC'
		));
	//	pr($venue);
		return $venue;
	}
}
